home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / ui / components / example / CheckboxDemo.java < prev    next >
Encoding:
Java Source  |  1997-07-13  |  2.0 KB  |  60 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.awt.*;
  18. import java.applet.Applet;
  19.  
  20. public class CheckboxDemo extends Applet {
  21.  
  22.     public void init() {
  23.         Panel p1, p2;
  24.         Checkbox cb1, cb2, cb3; //independent checkboxes
  25.         Checkbox cb4, cb5, cb6; //only one of these three can be selected
  26.         CheckboxGroup cbg;
  27.  
  28.         //Build first panel, which contains independent checkboxes
  29.         cb1 = new Checkbox();
  30.         cb1.setLabel("Checkbox 1");
  31.         cb2 = new Checkbox("Checkbox 2");
  32.         cb3 = new Checkbox("Checkbox 3");
  33.         cb3.setState(true);
  34.         p1 = new Panel();
  35.         p1.setLayout(new FlowLayout());
  36.         //Using a GridLayout didn't work--kept box and text too far apart.
  37.         p1.add(cb1);
  38.         p1.add(cb2);
  39.         p1.add(cb3);
  40.  
  41.         //Build second panel, which contains a checkbox group
  42.         cbg = new CheckboxGroup();
  43.         cb4 = new Checkbox("Checkbox 4", cbg, false);
  44.         cb5 = new Checkbox("Checkbox 5", cbg, false);
  45.         cb6 = new Checkbox("Checkbox 6", cbg, false);
  46.         p2 = new Panel();
  47.         p2.setLayout(new FlowLayout());
  48.         p2.add(cb4);
  49.         p2.add(cb5);
  50.         p2.add(cb6);
  51.  
  52.         //Add panels to the Applet. 
  53.         setLayout(new GridLayout(0, 2));
  54.         add(p1);
  55.         add(p2);
  56.  
  57.         validate();
  58.     }
  59. }
  60.